import {list} from "../../../api/warehouse"

Page({
    data: {
        inputValue:'321',
        options:[],
        placeholder:'请输入油库名',
        keyword:'',
        pageNum:1,
        pageSize:10,
        supplierId:''
    },
    onLoad(option){
        this.data.supplierId = option.supplierId
        this.setData({
            supplierId:this.data.supplierId
        })
    },
    onShow(){
        this.getList()
    },
    handleQuery(){
        this.data.options = []
        this.setData({
            options:this.data.options
        })
        this.getList()
    },
    keywordUpdate(e){
        this.data.keyword = e.detail.value
        this.data.options = []
        this.setData({
            keyword: this.data.keyword,
            options:this.data.options
        })
        this.getList()
    },
    getList(){
        let params = {
            type:1,
            keyword:this.data.keyword,
            pageNum:this.data.pageNum,
            pageSize:this.data.pageSize,
            customerId:this.data.supplierId
        }
        list(params).then(res=>{
            res.data.data.forEach(item=>{
                this.data.options.push(item)
            })
            this.setData({
                options:this.data.options
            })
        })
    },
    chooseSeller(e){
        let pages = getCurrentPages();
        let prevPage = pages[pages.length-2];
        prevPage.setData({
            warehouseName: e.currentTarget.dataset.item.name,
            warehouseId: e.currentTarget.dataset.item.id
        });
        wx.navigateBack({
            delta: 1,
        })
    },
    toAttestation(){
        wx.navigateTo({
            url:'/pages/oilStore/addOilStore'
        })
    },
    onPullDownRefresh(){
        this.data.pageNum = 1
        this.data.options = []
        this.setData({
            pageNum:this.data.pageNum,
            options:this.data.options
        })
        this.getList()
        let settime = setTimeout(()=>{
            wx.stopPullDownRefresh()
            clearTimeout(settime)
        },1000)
    },
    onReachBottom(){
        this.data.pageNum = this.data.pageNum + 1
        this.setData({
            pageNum:this.data.pageNum
        })
        this.getList()
    }

})